int reverse(int number) {
    int rev = 0;
    int sign = (number < 0) ? -1 : 1;
    number = (number < 0) ? -number : number;

    while (number > 0) {
        rev = rev * 10 + number % 10;
        number /= 10;
    }

    return sign * rev;
}
